<?php
	class database
	{
	   
		var $sql = "";
		var $connection = "";
		var $cursor = null;	

		function database()
		{
			include('config.inc');
            
			$this->connection = @mysql_connect($hostname,$db_user,$db_pass);
			if( !$this->connection )
				die("Trang Web Đang Bảo Trì, Vui Lòng Quay Lai Sau | Error Code : 1.1");
				
			if( !mysql_select_db($db_name,$this->connection) )
                die("Trang Web Đang Bảo Trì, Vui Lòng Quay Lai Sau | Error Code : 1.2");
		}
        				
		function SetQuery($sql)	
		{
			$this->sql = $sql;
		}
		
		function Query()	
		{
			mysql_query("set names 'utf8'");
            
			$this->cursor = mysql_query($this->sql,$this->connection) or die (mysql_errno($this->connection));
            
			return $this->cursor;
		}
        
		function LoadAllRow()
		{
			if(!($cur = $this->query()))
			{
				return null;
			}
            
			$array = array();
            
			while($row = mysql_fetch_assoc($cur))
			{
				$array[] = $row;
			}
            
			mysql_free_result($cur);
            
			return $array;
		}
        
		function LoadOneRow()
		{
		  
			if(!($cur = $this->query()))
			{
				return null;
			}
            
			$row = mysql_fetch_assoc($cur);
            
			mysql_free_result($cur);
            
			return $row;
		}
        
		function disconnect()
		{
			mysql_close($this->connection);
		}
	}
?>